package com.ld.security.server.admin.modules.msg.service.impl;


import com.ld.security.common.core.anno.EventKey;
import com.ld.security.common.core.util.StringUtil;
import com.ld.security.common.mybatis.base.po.PagePo;
import com.ld.security.common.mybatis.base.service.*;
import com.ld.security.common.mybatis.base.vo.PageVo;
import com.ld.security.common.mybatis.util.JdbcUtil;
import com.ld.security.server.admin.modules.msg.constant.MsgGroupNewsUserConstant;
import com.ld.security.server.admin.modules.msg.service.IMsgGroupNewsService;

import com.ld.security.server.admin.modules.msg.entity.MsgGroupNewsEntity;

import com.ld.security.server.admin.modules.msg.service.IMsgGroupNewsUserRelService;
import com.ld.security.server.admin.modules.msg.vo.MyGroupMsgVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.CompletableFuture;

@Service
@Transactional
public class MsgGroupNewsServiceImpl  extends ISuperServiceImpl<MsgGroupNewsEntity>
implements
        IMsgGroupNewsService {


        @Autowired
        IMsgGroupNewsUserRelService iMsgGroupNewsUserRelService;


        @Override
        public int save(MsgGroupNewsEntity entity) {
                //新增才推送
                boolean init = StringUtil.isNull(entity.getId());
                if(StringUtil.isNull(entity.getLabel())){

                }
                int total = super.save(entity);
                //异步推送消息
                if(init){
                        CompletableFuture.runAsync(() -> {
                                try{
                                        iMsgGroupNewsUserRelService.pushMsg(entity);
                                }catch (Exception e){
                                        e.printStackTrace();
                                }

                        });
                }


                return total;
        }




        @Override
        public PageVo<MyGroupMsgVo> myGroupMsg(PagePo<MyGroupMsgVo> po) {
                return JdbcUtil.page(po);
        }
}
